<?php
// list page
require_once 'view/adm/content/pages.index.php';


class PagesIndexPage extends PageController {

	var $form;

    function PagesIndexPage() {
        parent::PageController();

        $this->form =& new FormController();
        $this->form->addChild('apply', new ButtonController(new Delegate($this, 'apply')));
        $this->form->setDefaultChild('apply');

        	$this->form->addRule(new Handle('NumericRangeRule', array('page_id',0)));
        	//$this->form->addRule(new Handle('NumericRangeRule', array('category1',0)));
        	$this->form->addRule(new Handle('NumericRangeRule', array('start_day',1,31)));
            $this->form->addRule(new Handle('NumericRangeRule', array('end_day',1,31)));
            $this->form->addRule(new Handle('NumericRangeRule', array('start_year',2000,2999)));
            $this->form->addRule(new Handle('NumericRangeRule', array('end_year',2000,2999)));

        $this->registerOnLoadListener(new Delegate($this, 'load'));
        $this->addChild('FilterForm', $this->form);
        $this->setDefaultChild('FilterForm');



        $this->setDefaultView(new Handle('PagesListView', array('/adm/content/pages.index.html')));


        $this->addView('success', WACT_DEFAULT_VIEW);
        $this->addView('notfound', WACT_DEFAULT_VIEW);
        $this->addView('delete', new Handle('RedirectView', array('/delete')));


    }

     function load(&$source, &$request, &$responseModel) {
        // check for "GET" parameters related to filters
        if ( $request->hasParameter('filter_type') )  {
        	$filter_type = $request->getParameter('filter_type');
        	$type = $request->getParameter('type');
        	//print 'Filter: '.$filter_type.' '.$type;
        	if ($filter_type)  {
          		$responseModel->set('filter_type',$filter_type);
          		$responseModel->set('type',$type);
                Session::saveResponseModel($responseModel,'filter.pages');
        	}
        }
     }

    //apply filter
    //save filter response model into session
    function apply(&$source, &$request, &$responseModel) {
    	//print 'Applying filter...';
    	//if ( !$request->hasPostProperty('filter_type') )  {
            //$responseModel->remove('filter_type');
            //$responseModel->remove('type');
            //print 'Removing type filter...';
    	//}
    	Session::saveResponseModel($responseModel,'filter.pages');
    }
}

?>